<?php
    // $panier = \WZ_Store::getInstance('panier')->getStore();
    // $panier->delete();
    // $panier->setProducts(array('item' => 'TV', 'price' => 200));
    // $panier->setDate(new \Datetime());
    // $panier->save();
    // var_dump($panier->getProducts());
    // var_dump($panier->getDate());
    // exit;
    
    class WZ_Store
    {
        public $store;
        static $_instance = array();
		
		// singleton
		public static function &getInstance($store = 'myStore') 
		{
            if (!array_key_exists($store, self::$_instance)) {
                self::$_instance[$store]  = new self($store);
            }
            return self::$_instance[$store];
		}
        
        public function __construct($store)
        {
            $s = self::session();
            if (null === $s->$store) {
                $storeObject = new WZ_StoreObject;
                $storeObject->storeName = $store;
                $s->$store = $storeObject;
            }
            self::set('store', $s->$store);
        }
        
        public static function session()
        {
            \Zend_Session::start();
            return new \Zend_Session_Namespace('WZStores');
        }
        
        public function set($key, $value)
        {
            $this->$key = $value;
        }
        
        public function get($key)
        {
            if (isset($this->$key)) {
                return $this->$key;
            }
            return null;
        }
        
        public function getStore()
        {
            return self::get('store');
        }
    }
    